package cn.mygweb.admin.modules.web.service.impl;

import java.util.List;

import org.assertj.core.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.mygweb.admin.modules.web.mapper.MessageMapper;
import cn.mygweb.admin.modules.web.pojo.Message;
import cn.mygweb.admin.modules.web.service.MessageService;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/** 
* <p>Title: MessageServiceImpl.java</p>
* <p>Description: 用户留言信息业务层实现类</p>  
* @author gxb 
* @date 2019年7月7日 
* <p>Copyright: Copyright (c) 2019</p>
* <p>Company: www.mygweb.cn</p> 
*/
@Service
public class MessageServiceImpl implements MessageService {
	
	@Autowired
	private MessageMapper messageMapper;	

	/* (non-Javadoc)
	 * <p>Title: queryListByExample</p>
	 * <p>Description: </p>
	 * @param message
	 * @return
	 * @see cn.mygweb.admin.modules.web.service.MessageService#queryListByExample(cn.mygweb.admin.modules.web.pojo.Message)
	 */
	@Override
	@Transactional(propagation=Propagation.SUPPORTS)
	public List<Message> queryListByExample(Message message) {
		Example example = new Example(Message.class);
		example.setOrderByClause("time desc");//按照时间倒序排列
		return messageMapper.selectByExample(example);
	}

	/* (non-Javadoc)
	 * <p>Title: save</p>
	 * <p>Description: </p>
	 * @param message
	 * @see cn.mygweb.admin.modules.web.service.MessageService#save(cn.mygweb.admin.modules.web.pojo.Message)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void save(Message message) {
		message.setStatus(0);
		messageMapper.insert(message);
	}

	/* (non-Javadoc)
	 * <p>Title: update</p>
	 * <p>Description: </p>
	 * @param message
	 * @see cn.mygweb.admin.modules.web.service.MessageService#update(cn.mygweb.admin.modules.web.pojo.Message)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void update(Message message) {
		messageMapper.updateByPrimaryKeySelective(message);
	}

	/* (non-Javadoc)
	 * <p>Title: batchDelByIds</p>
	 * <p>Description: </p>
	 * @param ids
	 * @see cn.mygweb.admin.modules.web.service.MessageService#batchDelByIds(java.lang.String[])
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void batchDelByIds(String[] ids) {
		Example example = new Example(Message.class);
		Criteria criteria = example.createCriteria();
		List<Object> idList = Arrays.asList(ids);
		criteria.andIn("id", idList);
		messageMapper.deleteByExample(example);
	}

	/* (non-Javadoc)
	 * <p>Title: selectUnreadMsg</p>
	 * <p>Description: </p>
	 * @param count
	 * @return
	 * @see cn.mygweb.admin.modules.web.service.MessageService#selectUnreadMsg(java.lang.Integer)
	 */
	@Override
	public List<Message> selectUnreadMsg(Integer count) {
		List<Message> unreadMsgList = messageMapper.selectUnreadMsg(count);
		return unreadMsgList;
	}

}
